package com.maket.scxx.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.maket.scxx.domain.CpProduct;
import com.maket.scxx.domain.JybzInspectionStandardsAndCpProduct;
import com.maket.scxx.domain.JyxmInspectionItemsAndJybzStandards;
import com.maket.scxx.service.CpProductService;
import com.maket.scxx.service.JybzInspectionStandardsAndCpProductService;
import com.maket.scxx.service.JyxmInspectionItemsAndJybzStandardsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.maket.scxx.domain.JybzInspectionStandard;
import com.maket.scxx.service.IJybzInspectionStandardService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 检验标准Controller
 * 
 * @author ruoyi
 * @date 2024-06-25
 */
@RestController
@RequestMapping("/standard")
public class JybzInspectionStandardController extends BaseController
{
    @Autowired
    private IJybzInspectionStandardService jybzInspectionStandardService;
    @Autowired
    private JybzInspectionStandardsAndCpProductService jybzInspectionStandardsAndCpProductService;
    @Autowired
    private JyxmInspectionItemsAndJybzStandardsService jyxmInspectionItemsAndJybzStandardsService;

    /**
     * 查询检验标准列表
     */
    @RequiresPermissions("scxx:standard:list")
    @GetMapping("/list")
    public TableDataInfo list(JybzInspectionStandard jybzInspectionStandard)
    {
        startPage();
        List<JybzInspectionStandard> list = jybzInspectionStandardService.selectJybzInspectionStandardList(jybzInspectionStandard);
        return getDataTable(list);
    }

    /**
     * 查询产品列表
     */
    @Autowired
    private CpProductService cpProductService;
    @RequiresPermissions("scxx:standard:list")
    @GetMapping("/cp")
    public TableDataInfo list(CpProduct cpProduct)
    {
        startPage();
        List<CpProduct> list = cpProductService.getAll(cpProduct);
        return getDataTable(list);
    }

    /**
     * 导出检验标准列表
     */
    @RequiresPermissions("scxx:standard:export")
    @Log(title = "检验标准", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JybzInspectionStandard jybzInspectionStandard)
    {
        List<JybzInspectionStandard> list = jybzInspectionStandardService.selectJybzInspectionStandardList(jybzInspectionStandard);
        ExcelUtil<JybzInspectionStandard> util = new ExcelUtil<JybzInspectionStandard>(JybzInspectionStandard.class);
        util.exportExcel(response, list, "检验标准数据");
    }

    /**
     * 获取检验标准详细信息
     */

    @RequiresPermissions("scxx:standard:query")
    @GetMapping(value = "/{mbCode}")
    public AjaxResult getInfo(@PathVariable("mbCode") String mbCode)
    {
        List<JybzInspectionStandardsAndCpProduct> cpProducts = jybzInspectionStandardsAndCpProductService.selectWithBzCode(mbCode);
        List<JyxmInspectionItemsAndJybzStandards> jyxmInspectionItemsAndJybzStandards = jyxmInspectionItemsAndJybzStandardsService.selectWithBzCode(mbCode);
        JybzInspectionStandard jybzInspectionStandard = jybzInspectionStandardService.selectJybzInspectionStandardByMbCode(mbCode);
        jybzInspectionStandard.setCp(cpProducts);
        jybzInspectionStandard.setXm(jyxmInspectionItemsAndJybzStandards);
        return success(jybzInspectionStandard);
    }

    /**
     * 新增检验标准
     */
    @RequiresPermissions("scxx:standard:add")
    @Log(title = "检验标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JybzInspectionStandard jybzInspectionStandard)
    {
        return toAjax(jybzInspectionStandardService.insertJybzInspectionStandard(jybzInspectionStandard));
    }

    /**
     * 修改检验标准
     */
    @RequiresPermissions("scxx:standard:edit")
    @Log(title = "检验标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JybzInspectionStandard jybzInspectionStandard)
    {
        return toAjax(jybzInspectionStandardService.updateJybzInspectionStandard(jybzInspectionStandard));
    }

    /**
     * 删除检验标准
     */
    @RequiresPermissions("scxx:standard:remove")
    @Log(title = "检验标准", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mbCodes}")
    public AjaxResult remove(@PathVariable String[] mbCodes)
    {
        return toAjax(jybzInspectionStandardService.deleteJybzInspectionStandardByMbCodes(mbCodes));
    }
}
